package com.sdry.product.waitingarea.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sdry.product.waitingarea.entity.StayStock;
import com.sdry.product.waitingarea.mapper.StayStockMapper;
import com.sdry.product.waitingarea.service.StayStockService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (StayStock)表服务实现类
 *
 * @author makejava
 * @since 2020-03-17 16:19:06
 */
@Service("stayStockService")
public class StayStockServiceImpl implements StayStockService {
    @Resource
    private StayStockMapper stayStockDao;

    /**
     * 通过ID查询单条数据
     *
     * @param csrid 主键
     * @return 实例对象
     */
    @Override
    public StayStock queryById(Long csrid) {
        return this.stayStockDao.queryById(csrid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<StayStock> queryAllByLimit(int offset, int limit) {
        return this.stayStockDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param stayStock 实例对象
     * @return 实例对象
     */
    @Override
    public StayStock insert(StayStock stayStock) {
        this.stayStockDao.insert(stayStock);
        return stayStock;
    }

    /**
     * 修改数据
     *
     * @param stayStock 实例对象
     * @return 实例对象
     */
    @Override
    public StayStock update(StayStock stayStock) {
        this.stayStockDao.update(stayStock);
        return this.queryById(stayStock.getCsrid());
    }

    /**
     * 通过主键删除数据
     *
     * @param csrid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long csrid) {
        return this.stayStockDao.deleteById(csrid) > 0;
    }

    @Override
    public List<StayStock> queryStayStockPage(StayStock stayStock) {
        return stayStockDao.queryAll(stayStock);
    }

    @Override
    public Long queryStayStockTotal(StayStock stayStock) {
        QueryWrapper<StayStock> queryWrapper = new QueryWrapper<>();
        Integer integer = stayStockDao.selectCount(queryWrapper);
        return integer.longValue();
    }
}